

$(function () {
    console.log("加载中.....");
    // copyFile();



    if (window.addEventListener) {
        window.addEventListener("load", csh, false);
    } else if (window.attachEvent) {
        window.attachEvent("onload", csh);
    } else {
        window.onload = csh;
    }

})

function csh() {
    //设置语言
    testttttt();
}

function copyFile(){
    var fields = ["myfile","sdfsd"];
    $.ajax({
        url:"/quotation/TestAttrCopya",
        data:{instanceId:"b739a4fc-db20-400e-902f-043e10304e35",attaFields:fields},
        dataType: "json",
        async: true,
        contentType: 'application/json',
        success: function (data) {

            console.log(data);

        }
    })
}

function testttttt() {


    var atta = $.MvcSheetUI.GetElement("myfile").SheetAttachment();

    var array = [{
        Code: "d104bbe1-a1d2-4dd0-99a7-201fc6ca4cd1",
        ContentType: "application/vnd.ms-excel",
        Name: "管理范围内事项导入模板.xls",
        Size: 18944,
        Url: "/Portal/ReadAttachment/Read?BizObjectSchemaCode=myWorkflow&BizObjectID=null&AttachmentID=2d6df219-cd56-4eb2-b06e-6470552c6190&OpenMethod=0"}]

    // atta.V = array;

    // atta.CreateFileElement(array[0].Code, array[0].Name, array[0].Size, array[0].Url, array[0].ContentType);
    // atta.InitValue();

    var url = array[0].Url;
    var contentType = array[0].ContentType;
    var name = array[0].Name;

    const xhr = new XMLHttpRequest()
    xhr.open('post', url, true);
    // 请求类型 bufffer
    xhr.responseType = 'arraybuffer'
    xhr.onload = function () {
        if (xhr.status === 200 || xhr.status === 304) {
            // 将后台 buffer 转换为 blob
            let blob = new Blob([xhr.response], {type: contentType})
            // 创建blob链接
            var file = new File([blob],name);
            console.log(file);

        }
    }
    xhr.send()




}